package org.filecollector.filecontroller.virtualcatalogue.virtualfile;

import lombok.Getter;

import java.nio.file.Path;
import java.util.Optional;
import java.util.OptionalLong;

/**
 * Exception Class that extends {@link RuntimeException} and provide work with troubles of file working
 * <p>
 *     Contains {@link InvalidFileException#filepath} and {@link InvalidFileException#reason} to allow make
 *     the Troubles Hunter.
 * </p>
 */
public class InvalidFileException extends RuntimeException {
    @Getter FileTroubles reason;
    Optional<Path> filepath;
    OptionalLong id;

    /**
     * @return Path in {@link Optional} decorer
     */
    public Optional<Path> getPath() {
        return filepath;
    }

    /**
     * Construct default Exception
     * @param ex comment describes situation
     * @see RuntimeException
     */
    public InvalidFileException(String ex) {
        super(ex);
        reason = FileTroubles.UNKNOWN_TROUBLES;
        filepath = null;
    }

    /**
     * Construct default exception with {@link FileTroubles} flag
     * @param ex comment describes situation
     * @param troubles parameter that flagging troubles specific
     */
    public InvalidFileException(String ex, FileTroubles troubles) {
        this(ex);
        reason = troubles;
    }

    /**
     * Construct default exception with {@link FileTroubles} flag and path to problem file
     * @param ex comment describes situation
     * @param troubles parameter that flagging troubles specific
     * @param path path to problem file
     */
    public InvalidFileException(String ex, FileTroubles troubles, Path path) {
        this(ex, troubles);
        filepath = Optional.of(path);
    }

    /**
     * Construct default exception with {@link FileTroubles} flag and problem id
     * @param ex comment describes situation
     * @param troubles parameter that flagging troubles specific
     * @param id path to problem file
     */
    public InvalidFileException(String ex, FileTroubles troubles, Long id) {
        this(ex, troubles);
        this.id = OptionalLong.of(id);
    }
}
